//验证码
function loadMyk() {
    var yanzhe=window.session_storage.getItem("yanzhe");
    if(yanzhe == "undefined"){
        var yanzhe=""
    }
    var user_data = {
        codeID:yanzhe,
    }
    var succCallBack = function (data, status, response) {

            var str='';
            window.session_storage.setItem('yanzhe',data.data.codeID);
            window.session_storage.setItem('zhancon',data.data.code);
            console.log(data.data.code)
            $("#zhang_text").html(data.data.code);
            var antin = $('#antin').val("")

        // if(data.result==1){
        // console.log(data.data.code)

        // }
    };
    return web.doAjax(root.accessInter.imgIdentifyCode,'post',web.toMyJson(user_data), succCallBack);
}
//登录校验
function signin() {
    var b = new Base64();
    // document.cookie="loginData"+"="+200+"; "
    // var x = document.cookie;
    // console.log(x)
    // var str = b.encode("1234");
    // console.log(str);
    // str = b.decode(str);
    // console.log(str);
    var quzhi=JSON.parse(web.readCookie("loginData"))
    var account = $('#account').val();
    var Pass = $('#Password').val();
    var antin = $('#antin').val().toLowerCase();//不区分大小写
    // var Password =hex_md5(Pass);
    var Password =b.encode(Pass);
    var zhancon=window.session_storage.getItem("zhancon").toLowerCase();//不区分大小写
    var uuid=window.session_storage.getItem("yanzhe")
    if(account==""){
        $.Huimodalalert('账号不能为空',2000)
    }else if(Password==""){
        $.Huimodalalert('密码不能为空',2000)
    }else if(antin!=zhancon){
        $.Huimodalalert('您输入的验证码不正确',2000)
        loadMyk()
        $("#antin").val("")
        return false
    }else{
        $.ajax({
            type: 'post',
            // url: 'http://65.110.8180/login_api',
            url:root.accessInter.login_api,
            data: { loginname:account,
                password:Password,
                code:zhancon,
                codeID:uuid
            },
            dataType: 'json',
            success: function (data) {
                if(data.code=="200"){
                    // console.log(data.data)
                    var loginData=data.data
                    window.session_storage.setItem('token',data.data.tokenID);
                    window.localStorage.setItem('loginData',JSON.stringify(loginData))
                    document.cookie="user_id="+data.data.user.user_ID+";path=/";
                    setTimeout(function(){
                        window.location.href="index.html"
                    },200)
                }else if(data.code=="800"){
                    $.Huimodalalert('验证码已过期',2000)
                    loadMyk()
                    $("#antin").val("")
                }else{
                    $.Huimodalalert('用户名或密码有误',2000)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        })
    }
}
//登录调用
$(document).keypress(function() {
    if(event.keyCode == "13"){
        signin()
    }
});
$('#bottm').bind('click',function() {
    signin()
})
//登录按钮 是否高亮
function Highlight() {
    var account= $('#account').val(),
        Password= $('#Password').val(),
        antin= $('#antin').val();
    if(account != '' || Password != '' ||antin != ''){
        $("#bottm").removeClass('cilocboot')
    }
    if (account=="" && Password=="" && antin  == ''){
        $("#bottm").addClass('cilocboot')
    }

}


